/**
 * 判断一个string是否为合法的ip地址
 * @param str
 */

function validIpAddr(str){
    const length = str.length
    if(length<7 || length > 15 || str ===' ') {
        return false
    }
    const parts = str.split('.')
    const len  = parts.length
    for (let i = 0; i < len; i++) {
        if(isNaN(parts[i])){
            return false
        }
        if(parts[i]<0 || parts[i]>255){
            return false
        }
    }
    return true
}

const str = '192.22.12.117'
const str1 = 'ci.109.255.8'

console.log(validIpAddr(str));
console.log(validIpAddr(str1));
